/* 
 * File:   Object.cpp
 * Author: paula
 * 
 * Created on 22 de octubre de 2014, 16:50
 */

#include "Object.h"

Object::Object(struct ObjectInit data, SDL_Renderer *render, int type, int image) {

    this->data = data;

    this->pathType = "";
    switch (type) {
        case RECTANGLE:
            this->pathType = "Rectangle";
            break;
        case CIRCLE:
            this->pathType = "Circle";
            break;
        case PARALLELOGRAM:
            this->pathType = "Parallelogram";
            break;
        case TRAPEZIUM:
            this->pathType = "Trapezium";
            break;
        case TRIANGLE:
            this->pathType = "Triangle";
            break;
        case PENTAGON:
            this->pathType = "Pentagon";
            break;
        case HEXAGON:
            this->pathType = "Hexagon";
            break;
        case BONUS:
            this->pathType = "Bonus";
            break;
        case BULLET:
            this->pathType = "Circle";
            break;
    }
    this->pathImage = to_string(image);
    this->path = "Img/" + pathType + "/" + pathImage + ".png";
    //    myLogFile->getInstance(MY_LOG_MODE);
    this->dot = new Dot(this->data.x, this->data.y, this->data.width, this->data.height);
    this->gRenderer = render;
    this->loadMedia(path);
}

int Object::getCharacterId() {
    return this->data.idCharacter;
}

float Object::getPosX() {
    return this->dot->getPos()->x;
}

float Object::getPosY() {
    return this->dot->getPos()->y;
}

struct ObjectInit Object::getData() {
    return this->data;
}

void Object::actualize() {

    this->dot->setPos(this->data.x, this->data.y);
    this->dot->setSize(this->data.width, this->data.height);
    this->dot->sizeDotWorldToPixels();
    this->dot->dotWorldToPixels();

}

void Object::draw() {

    b2Vec2* pos;
    b2Vec2* size;
    size = this->dot->getSize();
    pos = this->dot->getPos();

    SDL_Rect* settings = new SDL_Rect();

    settings->w = size->x;
    settings->h = size->y;
    settings->x = pos->x;
    settings->y = pos->y;

    settings->x = settings->x - (settings->w / 2);
    settings->y = settings->y - (settings->h / 2);

    SDL_RenderCopyEx(gRenderer, image->getTexture(), NULL, settings, (this->data.rot)*58, NULL, SDL_FLIP_NONE);

    delete settings;

}

Object::Object(const Object& orig) {
}

void Object::loadMedia(string path) {

    this->image = new SBSImage();
    this->image->loadMedia(path, &gRenderer);

}

void Object::updateData(struct ObjectInit data) {
    this->data = data;
}

Object::~Object() {    
    delete this->image;
    delete this->dot;
}

